home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / smixc130.zip / MIXTEST.C < prev    next >
C/C++ Source or Header  |  1997-06-06  |  6KB  |  250 lines

  1. /*      SMIXC is Copyright 1995 by Ethan Brodsky.  All rights reserved      */
  2.  
  3. /* ██ MIXTEST.C ███████████████████████████████████████████████████████████ */
  4.  
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9.  
  10. #include "detect.h"
  11. #include "smix.h"
  12.  
  13. #define ON  1
  14. #define OFF 0
  15.  
  16. #define TRUE  1
  17. #define FALSE 0
  18.  
  19. #define XMSREQUIRED 200 /* k */
  20. #define SHAREDEMB    /* Undefine this to store all sounds in separate EMBs */
  21. #define NUMSOUNDS 6  /* Change this if you want to add more sounds         */
  22.  
  23. char *resource_file = "mixtest.snd";
  24.  
  25. char *sound_key[NUMSOUNDS] =
  26.   {
  27.     "JET",
  28.     "GUN",
  29.     "CRASH",
  30.     "CANNON",
  31.     "LASER",
  32.     "GLASS"
  33.   };
  34.  
  35. int baseio, irq, dma, dma16;
  36.  
  37. SOUND *sound[NUMSOUNDS];
  38.  
  39. void ourexitproc(void)
  40.   {
  41.     int i;
  42.  
  43.     for (i=0; i < NUMSOUNDS; ++i)
  44.       if (sound[i] != NULL)
  45.         free_sound(sound+i);
  46.  
  47. #ifdef SHAREDEMB
  48.     shutdown_sharing();
  49. #endif
  50.   }
  51.  
  52. void loadsounds(void)
  53.   {
  54.     int i;
  55.  
  56.     if (!init_xms())
  57.       {
  58.         printf("ERROR:  Can not initialize extended memory\n");
  59.         printf("HIMEM.SYS must be installed\n");
  60.         exit(EXIT_FAILURE);
  61.       }
  62.  
  63.     printf("Extended memory successfully initialized\n");
  64.     printf("Free XMS memory: %uk    ", getfreexms());
  65.     if (getfreexms() < XMSREQUIRED)
  66.       {
  67.         printf("ERROR:  Insufficient free XMS\n");
  68.         exit(EXIT_FAILURE);
  69.       }
  70.  
  71.     printf("Loading sounds\n");
  72. #ifdef SHAREDEMB
  73.     init_sharing();
  74. #endif
  75.     if (!open_sound_resource_file(resource_file))
  76.       {
  77.         printf("ERROR:  Can't load sound resource file\n");
  78.         exit(EXIT_FAILURE);
  79.       }
  80.  
  81.     for (i=0; i < NUMSOUNDS; i++)
  82.       load_sound(&(sound[i]), sound_key[i]);
  83.  
  84.     close_sound_resource_file();
  85.  
  86.     atexit(ourexitproc);
  87.   }
  88.  
  89. void freesounds(void)
  90.   {
  91.     int i;
  92.  
  93.     for (i=0; i < NUMSOUNDS; i++)
  94.       free_sound(sound+i);
  95. #ifdef SHAREDEMB
  96.     shutdown_sharing();
  97. #endif
  98.   }
  99.  
  100. void init(void)
  101.   {
  102.     printf("-------------------------------------------\n");
  103.     printf("Sound Mixing Library v1.30 by Ethan Brodsky\n");
  104.     if (!detect_settings(&baseio, &irq, &dma, &dma16))
  105.       {
  106.         printf("ERROR:  Invalid or non-existant BLASTER environment variable!\n");
  107.         exit(EXIT_FAILURE);
  108.       }
  109.     else
  110.       {
  111.         if (!init_sb(baseio, irq, dma, dma16))
  112.           {
  113.             printf("ERROR:  Error initializing sound card!\n");
  114.             exit(EXIT_FAILURE);
  115.           }
  116.       }
  117.  
  118.     printf("BaseIO=%Xh     IRQ%u     DMA8=%u     DMA16=%u\n", baseio, irq, dma, dma16);
  119.  
  120.     printf("DSP version %.1u.%.2u:  ", dspversion>>8, dspversion&0xFF);
  121.     if (sixteenbit)
  122.       printf("16-bit, ");
  123.     else
  124.       printf("8-bit, ");
  125.     if (autoinit)
  126.       printf("Auto-initialized\n");
  127.     else
  128.       printf("Single-cycle\n");
  129.  
  130.     init_mixing();
  131.     printf("\n");
  132.   }
  133.  
  134. void shutdown(void)
  135.   {
  136.     shutdown_mixing();
  137.     shutdown_sb();
  138.  
  139.     printf("\n");
  140.   }
  141.  
  142. int main(void)
  143.   {
  144.     int  jet            = 0;
  145.     int  randsound      = 1;
  146.     unsigned short rate = 22000;
  147.  
  148.     long counter;
  149.     char inkey;
  150.     int  num;
  151.     int  stop;
  152.  
  153.     randomize();
  154.  
  155.    /* Initialize SMIX */
  156.     init();
  157.  
  158.     loadsounds();
  159.  
  160.     printf("Press:\n");
  161.     printf("  J  Toggle jet engine\n");
  162.     printf("  R  Toggle random sounds\n");
  163.     printf("  1  Machine Gun\n");
  164.     printf("  2  Crash\n");
  165.     printf("  3  Cannon\n");
  166.     printf("  4  Laser\n");
  167.     printf("  5  Breaking glass\n");
  168.     printf("  <  Reduce sampling rate\n");
  169.     printf("  >  Increase sampling rate\n");
  170.     printf("  Q  Quit\n");
  171.  
  172.     stop = FALSE;
  173.     counter = 0;
  174.  
  175.     do
  176.       {
  177.        /* Increment and display counters */
  178.         counter++;
  179.         cprintf("%8lu %8lu %4u %8u", counter, intcount, voicecount, rate);
  180.         gotoxy(1, wherey());
  181.  
  182.        /* Maybe start a random sound */
  183.         if (randsound && (random(10000) == 0))
  184.           {
  185.            num = (random(NUMSOUNDS-1))+1;
  186.            start_sound(sound[num], num, OFF);
  187.           }
  188.  
  189.        /* Start a sound if a key is pressed */
  190.         if (kbhit())
  191.           {
  192.             inkey = getch();
  193.  
  194.             if ((inkey == 'J') || (inkey == 'j'))
  195.              /* Jet engine */
  196.               {
  197.                 jet = !jet;
  198.                 if (jet)
  199.                   start_sound(sound[0], 0, ON);
  200.                 else
  201.                   stop_sound(0);
  202.               }
  203.             else if ((inkey == 'R') || (inkey == 'r'))
  204.              /* Toggle random sounds */
  205.               randsound = !randsound;
  206.             else if ((inkey >= '0') && (inkey <= '9'))
  207.              /* Start a sound */
  208.               {
  209.                 num = inkey - '0'; /* Convert to integer */
  210.                 if (num < NUMSOUNDS)
  211.                   start_sound(sound[num], num, FALSE);
  212.               }
  213.             else if ((inkey == '<') || (inkey == ','))
  214.              /* Reduce sampling rate */
  215.               {
  216.                 rate -= 250;
  217.                 if (rate < 5000)
  218.                   rate = 5000;
  219.                 set_sampling_rate(rate);
  220.               }
  221.             else if ((inkey == '>') || (inkey == '.'))
  222.              /* Increase sampling rate */
  223.               {
  224.                 rate += 250;
  225.                 if (rate > 48000U)
  226.                   rate = 48000U;
  227.                 set_sampling_rate(rate);
  228.               }
  229.             else
  230.              /* Terminate */
  231.               stop = TRUE;
  232.           }
  233.       }
  234.     while (!stop);
  235.  
  236.     printf("\n");
  237.  
  238.    /* Stop the jet engine */
  239.     if (jet)
  240.       stop_sound(0);
  241.  
  242.    /* Shut down SMIX */
  243.     shutdown();
  244.  
  245.    /* Deallocate sounds */
  246.     freesounds();
  247.  
  248.     return(EXIT_SUCCESS);
  249.    }
  250.